class CatelogItem {
  String? id;
  String? title;
  String? author;
  String? url;
  bool? live;

  void fromJson(Map<String, dynamic> json){
    id = json["id"]?.toString();
    title = json["title"]?.toString();
    author = json["author"]?.toString();
    url = json["url"]?.toString();
    live = json["live"] == true;
  }

  Map<String, dynamic> toJson(){
    return <String, dynamic>{
      "id": id,
      "title": title,
      "author": author,
      "url": url,
      "live": live
    };
  }

  String getThumbnail() {
    var urlString = url.toString();
    if(live == true) {
      var fileName = Uri.parse(urlString).pathSegments.last;
      var replaceString = urlString.replaceAll(fileName, "");
      return '$replaceString$id.png';
    } else {
      return urlString;
    }
  }
}